package 剑指offer;

public class _66构建乘积数组 {
    public int[] constructArr(int[] a) {
        if(a == null || a.length == 0) {
            return new int[0];
        }
        int length = a.length;
        int[] left = new int[length];
        int[] right = new int[length];

        left[0] = right[length-1] = 1;

        for(int i = 1; i < length; i++) {
            left[i] = left[i-1] * a[i-1];
        }
        for(int i = length-2; i >= 0; i--) {
            right[i] = right[i+1] * a[i+1];
        }

        int[] res = new int[length];

        for(int i = 0; i < length; i++) {
            res[i] = left[i] * right[i];
        }
        return res;
    }
}
